package greedy.onClass.class2.exer02;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Bet {
    int b;
    int e;
    int t;

    Bet(int b, int e, int t) {
        this.b = b;
        this.e = e;
        this.t = t;
    }
}

public class Main {
    static int n, h;
    static int[] tree = new int[1000]; // 记录每个区间内，j位置上是否种树。
    static int ans = 0; // 记录区间的树
    static int count = 0; // 记录总共种植的树的数量

    static class BetComparator implements Comparator<Bet> {
        public int compare(Bet a, Bet b) {
            if (a.e == b.e) {
                return a.b - b.b;
            }
            return a.e - b.e;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        h = scanner.nextInt();
        Bet[] a = new Bet[h];
        for (int i = 0; i < h; i++) {
            a[i] = new Bet(scanner.nextInt(), scanner.nextInt(), scanner.nextInt());
        }
        scanner.close();

        Arrays.sort(a, new BetComparator());

        for (int i = 0; i < h; i++) {
            ans = 0;
            // 计算当前区间已经种植的树的数量
            for (int j = a[i].b; j <= a[i].e; j++) {
                ans += tree[j];
            }

            // 从右往左种树，直到满足最低要求
            for (int j = a[i].e; j >= a[i].b && ans < a[i].t; j--) {
                if (tree[j] == 0) { // 如果j位置没有种树
                    tree[j] = 1;
                    ans++;
                    count++;
                }
            }
        }

        System.out.println(count); // 输出总共种植的树的数量
    }
}